import { find, assign } from 'lodash'
import faker from 'faker/locale/zh_CN'
import { service, serviceForMock, request, requestForMock, mock } from '@/api/_service.js'
import * as tools from '@/api/_tools.js'

const users = [
  { username: 'admin', password: 'admin', uuid: 'admin-uuid', name: 'Admin' },
  { username: 'editor', password: 'editor', uuid: 'editor-uuid', name: 'Editor' },
  { username: 'user1', password: 'user1', uuid: 'user1-uuid', name: 'User1' }
]

/**
 * @description 登录
 * @param {Object} data 登录携带的信息
 */
export function SYS_USER_LOGIN (data = {}) {
  // 模拟数据
  mock
    .onAny('/login')
    .reply(config => {
      const user = find(users, tools.parse(config.data))
      return user
        ? tools.responseSuccess(assign({}, user, { token: faker.random.uuid() }))
        : tools.responseError({}, '账号或密码不正确')
    })
  // 接口请求
  return requestForMock({
    url: '/login',
    method: 'post',
    data
  })
}

//获取验证码
export function get_Code(){
  //解决跨域问题
 
  console.log(123)
  return request({
    url: 'api/auth/captcha',
    method: 'get',
  })
}

//登录
export function login(data){
  return request({
    url: 'stu/mongo/loginUser',
    method: 'post',
    data
  })
}

//学校教务系统登录
export function login_school(data){
  return request({
    url: 'shool',
    method: 'get',
    params: data
  })
}

//获取用户信息
export function get_userInfo(){
  return request({
    url: 'stu/common/getMsgByToken',
    method: 'get',

  })
}

//获取学校教务系统用户信息
export function get_userInfo_school(data){
  return request({
    url: 'shool/get_info',
    method: 'get',
    params: data
  })
}

//退出登录
export function logout_user(data){
  return request({
    url: 'api/auth/jwt/logout',
    method: 'delete',
    params:data
  })
}

//获取学校教务系统学生成绩
export function get_score_school(data){
  return request({
    url: 'stu/mongo/y/getScore',
    method: 'get',
    params: data
  })
}
//获取学期选项
export function get_xq(){
  return request({
    url: 'stu/mongo/y/getXq',
    method: 'get',
 
  })
}
//获取全部成绩
export function get_all_score(){
  return request({
    url: 'stu/mongo/y/getAllScore',
    method: 'get',

  })
}

//获取4级成绩
export function get_CET(){
  return request({
    url: 'stu/mongo/y/getCET',
    method: 'get',
   
  })
}

//获取课表
export function get_kebiao(data){
  return request({
    url: 'stu/mongo/y/getSchedule',
    method: 'get',
    params: data
  })
}